package lib.quasar.base.loading

import lib.quasar.base.dialog.LoadingDialog
import lib.quasar.base.frame.BaseActivity
import lib.quasar.base.frame.BasePresenter

import java.lang.ref.WeakReference

/**
 * description:
 * created by kalu on 2018/6/7 15:37
 */
open class LoadingManager private constructor() {

    private var mActivity: WeakReference<BaseActivity<BasePresenter>>? = null

    fun showDialog(activity: BaseActivity<BasePresenter>) {

        mActivity = WeakReference(activity)
        mDialog = WeakReference(LoadingDialog(mActivity?.get()!!))
        mDialog?.get()?.show()
    }

    fun closeDialog() {
        mDialog?.get()?.cancel()
    }

    private object SingletonHolder {
        val instance = LoadingManager()
    }

    companion object {
        private var mDialog: WeakReference<LoadingDialog>? = null

        val manager: LoadingManager
            get() = SingletonHolder.instance
    }
}
